package com.kongwg.java2;

import org.junit.Test;

/*
 * 包装类的使用
 * 
 * 
 */
public class Wrapper {
	
	
	//String类型--->基本数据类型、包装类、调用包装类的parseXxx(String s)
	@Test
	public void test5(){
		String str1 = "123";
		int num2 = Integer.parseInt(str1);
		System.out.println(num2);
		
		String str2 = "true1";
		boolean b1 = Boolean.parseBoolean(str2);
		System.out.println(b1);
				
		
	}
	//基本数据类型--->String数据类型
	@Test
	public void test4(){
		int num1 = 10;
		String str1 = num1 +"";
		float f = 3.14f;
		String str2 = String.valueOf(f);
		Double d1 = new Double(12.3);
		
		String str3 = String.valueOf(d1);
		System.out.println(str2);
		System.out.println(str3);//"12.3"
		
	}
	
	@Test
	public void test3(){
		Integer in1 = 22;
		int i1= in1;
		System.out.println(i1);
		float f1 = 3.14f;
		Float f = f1;
		System.out.println(f);
	}
	//包装类--->基本类型
	@Test
	public void test2(){
		Integer in1 = new Integer(11);
		int i1 = in1.intValue();
		System.out.println(i1+1);
		
		
		Float f1 = new Float(3.14);
		float f = f1.floatValue();
		System.out.println(f);
	}
	//基本类型--->包装类，调用包装类的构造器
	@Test
	public void test1(){
		int num1 = 10;
//		System.out.println(num1.toString());
		Integer in1 = new Integer(num1);
		System.out.println(in1.toString());
		
		
		Integer in2 = new Integer("123");
		System.out.println(in2.toString());
		
		
		//报异常
//		Integer in3 = new Integer("123abc");
//		System.out.println(in3.toString());
		
		
		Float f1 = new Float(12.3f);
		Float f2 = new Float("12.3");
		System.out.println(f1);
		System.out.println(f2);
		
		
		
		Boolean b1 = new Boolean(true);
		Boolean b2 = new Boolean("true");
		System.out.println(b1);
		System.out.println(b2);
		Boolean b3 = new Boolean("true123");
		System.out.println(b3);
		
		Order order = new Order();
		System.out.println(order.isMale);
		System.out.println(order.isFlag);
	}
}

class Order{
	boolean isMale;
	Boolean isFlag;
}
